package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.pojo.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.annotation.Target;
import java.util.List;

/**
 * @Description DishController
 * @Author luohai
 * @Date 2024-09-30
 */
@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品管理")
public class DishController {
    @Autowired
    DishService dishService;

    /**
     * 添加菜品
     * @param dishDTO
     * @return
     */
    @PostMapping
    public Result addDish(@RequestBody DishDTO dishDTO){
        dishService.addDish(dishDTO);
        return Result.success();
    }

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result searchAllDish(DishPageQueryDTO dishPageQueryDTO){
        PageResult pageResult=dishService.searchAllDish(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 菜品批量删除
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result deleteDishesById(@RequestParam List<Long> ids){
        dishService.deleteDishesById(ids);
        return Result.success();
    }

    /**
     * 根据ID查询菜品（数据回显）
     * @return
     */
    @GetMapping("/{dishId}")
    public Result searchDishById(@PathVariable Integer dishId){
        DishVO dish=dishService.searchDishById(dishId);
        return Result.success(dish);
    }

    /**
     * 根据ID修改菜品
     * @param dishDTO
     * @return
     */
    @PutMapping
    public Result modifyDishesById(@RequestBody DishDTO dishDTO){
        dishService.modifyDishesById(dishDTO);
        return Result.success();
    }

    /**
     * 根据分类id查询菜品
     * @return
     */
    @GetMapping("/list")
    public Result queryDishesByCategoryId(Long categoryId){
        List<DishVO> dish=dishService.queryDishesByCategoryId(categoryId);
        return Result.success(dish);
    }

}
